package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.systemDocumentPojo;
import com.example.service.systemDocumentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * ClassName:systemDocumentController
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/7/27 23:04
 * @Version 1.0
 */
@Slf4j
@RestController
public class systemDocumentController {
    @Autowired
    private systemDocumentService systemDocumentService;
    //插入一行，只有文件名称
    @PostMapping("/insertSystemDocument")
    public Result insertSystemDocument(@RequestBody String filedVal){
        //输入一个字段名称和字段变量，插入一行。这一行只保留了一个参数，其他为空。
        systemDocumentService.insertByOneFiledName("docName",filedVal);
        return Result.success("保存成功");
    }
    //查询所有不同的体系文件名称
    @PostMapping("/querySystemDocName")
    public Result querySystemDocName(){
        List<systemDocumentPojo> systemDocumentPojoList=systemDocumentService.querySystemDocName();
        return Result.success(systemDocumentPojoList);
    }
    //写入一个体系文件，并且修改体系文件地址
    @PostMapping("/addPDFSystemDocument")
    public Result addPDFSystemDocument(@RequestParam("file") MultipartFile file, @RequestParam Integer id, @RequestParam String fieldName, @RequestParam String fieldVal, @RequestParam String fileName){
        //上传照片的接口
        String allName = systemDocumentService.addPDFSystemDocument(file,id,fieldName,fieldVal,fileName);
        return Result.success(allName);
    }
    //根据传来的数据，进行修改一个字段，修改的字段为string类型。
    @PostMapping("/editFiledOneById")
    public Result editFiledOneById(@RequestBody Map<String,Object> parameters){
        String filedVal=systemDocumentService.editFiledOneById(parameters);
        return Result.success(filedVal);
    }
    //删除体系文件的PDF文档
    @PostMapping("/delFilePdfSystemDocument")
    public Result delFilePdfSystemDocument(@RequestBody Map<String,Object> parameters){
        String filedVal=systemDocumentService.delFilePdfSystemDocument(parameters);
        return Result.success(filedVal);
    }
}
